package com.blog.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileUtils {

    public static String saveFile(MultipartFile file, String uploadPath, String fileName) throws IOException {
        // 创建目录
        File dir = new File(uploadPath);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        
        // 保存文件
        Path path = Paths.get(uploadPath, fileName);
        Files.write(path, file.getBytes());
        
        return path.toString();
    }
} 